<include file="Public:header" />
<include file="Public:left" />
	<form action="" method="post" enctype="multipart/form-data" id="brandForm">
     <section>
      <h2><strong>数据导入</strong></h2>
      <ul class="ulColumn2">
        <li>
            <span class="item_name" style="width:120px;">项目类型：</span>
            <select name="type" >
                  <option value="0" >请选择项目类型</option>
                  <volist name="project_type" id="vo">
                    <option value="{$vo.id}">{$vo.type_name}</option>
                  </volist>
            </select>
        </li>
  	    <li>
            <span class="item_name" style="width:120px;">附件内容：</span>
            <input type="file" class="textbox textbox_295" name="file" id=""  value=""/>&nbsp;&nbsp;注：只能上传Excles文件,并且最好每个文件以1000条数据为适,当数据过大时请耐心等待不要关闭浏览器
        </li>
        <li>
            <span class="item_name" style="width:120px;"></span>
            <input type="button" class="link_btn" value="提交"/>
        </li>
      </ul>
     </section>
	</form>
  <section>
      <ul class="ulColumn2">
          <li>
              <span class="item_name" style="width:120px;float:left;">导入记录：</span>
              <div  class="textbox" style="width:1000px;height:400px;overflow-x: auto;float: left;">
                  <table class="table">
                      <tr>
                          <th>ID</th>
                          <th>文件名</th>
                          <th>新添加企业数目</th>
                          <th>项目新添加个数</th>
                          <th>时间</th>
                          <th>操作</th>
                      </tr>
                      <volist name="record_result" id="vo">
                      <tr>
                          <td>{$vo.id}</td>
                          <td>{$vo.file_name}</td>
                          <td>{$vo.enterprise_num}</td>
                          <td>{$vo.project_num}</td>
                          <td>{$vo.time|date="Y-m-d",###}</td>
                          <td align="center"><a class="inner_btn del" onclick="del_record(this)" id="{$vo.id}">删除</a></td>
                      </tr>
                      </volist>
                  </table>
              </div>
              &nbsp;&nbsp;注：删除文件以后则连同从文件读取导入的数据一并清除!
          </li>
      </ul>
  </section>
 </div>
</section>
<script>
  $(".link_btn").click(function(){
      if($("select[name='type']").val()=="0"){
          layer.alert("请选择项目类型!");
          return false;
      }


      var file = $(':file')[0].files[0];
      if(file){
          var file_name = $(':file')[0].files[0].name;
      }

      var formData = new FormData();
      formData.append('file',file);
      formData.append('type',$("select[name='type']").val());
      formData.append('file_name',file_name);

      $.ajax({
          url:"{:url('Export/index')}",
          type:'POST',
          data:formData,
          async:true,
          processData:false,
          contentType:false,
          beforeSend: function(){  
               ityzl_SHOW_LOAD_LAYER();
          }, 
          success:function(result){
              if(result.code == '0'){
                  layer.alert(result.msg);
              }else{
                  layer.alert(result.msg, {
                      btn: ['确定']
                  },
                  function (index, item) {
                      location.href = result.url;
                  });
              }
          }
          
      });
  });

  function del_record(obj){
      var record_id = $(obj).attr('id');
      var formData = new FormData();
      formData.append('record_id',record_id);

      layer.confirm('确定删除文件?', {
        btn: ['是','否'] //按钮
      }, function(){

          $.ajax({
            url:"{:url('Export/del_xls_record')}",
            type:'POST',
            data:formData,
            async:false,
            processData:false,
            contentType:false, 
            success:function(result){
                if(result.code == '0'){
                    layer.alert(result.msg);
                }else{
                    var index = layer.alert(result.msg, {
                      btn: ['确定']
                    },
                    function (index, item) {
                        $(obj).parent().parent().remove();
                        layer.close(index);
                    });
                }
            }
          
        });
      });
      $('.layui-layer-btn1').css('color','white');
  }

  function ityzl_SHOW_LOAD_LAYER(){
      //console.log('123');  
      layer.msg('导入中...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:1800*1000}) ;  
  }  
</script>
</body>
</html>
